package com.qkbb.admin.kuibu.qkbb.imageloader;

import java.io.File;

import android.os.Environment;
import android.os.StatFs;

import com.qkbb.admin.kuibu.qkbb.funcation.SDCardHelper;

/**
 * @author DigHammer
 * */
public class FileUtil {
	/** 保存到该文件夹下，当应用被删除的时候，该文件夹也会被系统删除 */
	public static String getImageCacheDirPath() {
		String path = null;
		File file = null;
		if (hasSDCard()) {
			path = SDCardHelper.getInstance().getSDCardBasePath() + File.separator + "keeboo";
			file = new File(path);
			if (!file.exists()) {
				file.mkdirs();
			}
			return path;
		} else {
			return null;
		}

	}

	public static boolean hasSDCard() {
		String status = Environment.getExternalStorageState();
		if (!status.equals(Environment.MEDIA_MOUNTED)) {
			return false;
		}
		return true;
	}

	public static boolean isSDHasFree() {
		// 取得SD卡文件路径
		File path = Environment.getExternalStorageDirectory();
		StatFs sf = new StatFs(path.getPath());
		// 获取单个数据块的大小(Byte)
		long blockSize = sf.getBlockSize();
		// 空闲的数据块的数量
		long freeBlocks = sf.getAvailableBlocks();
		// 返回SD卡空闲大小
		long freeSize = (freeBlocks * blockSize) / 1024 / 1024; // 单位MB
		if (freeSize >= 20) {
			return true;
		}
		return false;
	}
}
